//
//  LBViewController.m
//  LBVerticalPageView
//
//  Created by liuboliu on 08/25/2021.
//  Copyright (c) 2021 liuboliu. All rights reserved.
//

#import "LBViewController.h"
#import "LBVerticalPageContainerView.h"
#import "TPAskanswerSinglePageView.h"

@interface LBViewController () <TPVerticalPageContainerViewDelegate, LBVerticalPageContainerViewDataSource,LBVerticalPageViewCellDelegate>

@property (nonatomic, strong) LBVerticalPageContainerView *containerView;

@property (nonatomic, strong) NSMutableArray *array;

@end

@implementation LBViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.automaticallyAdjustsScrollViewInsets = NO;
    for (int i = 0; i < 10; i ++) {
        NSMutableArray *array = [NSMutableArray array];
        for (int j = 0; j < 10; j ++) {
            NSString *content = [NSString stringWithFormat:@"%d %d", i , j];
            [array addObject:content];
        }
        [self.array addObject:array];
    }
    
    self.view.backgroundColor = [UIColor blueColor];
    [self.view addSubview:self.containerView];
    
    [self.containerView reloadData];
    
	// Do any additional setup after loading the view, typically from a nib.
}

- (NSInteger)numberOfViewForVerticalPageContainerView:(LBVerticalPageContainerView *)rollingView
{
    return self.array.count;
}

- (LBVerticalPageViewCell *)verticalPageView:(LBVerticalPageContainerView *)rollingView viewAtIndex:(NSUInteger)index
{
    TPAskanswerSinglePageView *view = [rollingView dequeueReusableCellWithIdentifier:NSStringFromClass([TPAskanswerSinglePageView class])];
    NSArray *array = self.array[index];
    view.delegate = self;
    [view updateWithModel:array];
    return view;
}

#pragma mark - LBVerticalPageViewCellDelegate
- (void)verticalPageScrollViewDidScroll:(UIScrollView *)scrollView
{
    
}

- (void)verticalPageScrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate
{
    
}

#pragma mark - lazy load
- (LBVerticalPageContainerView *)containerView
{
    if (!_containerView) {
        _containerView = [[LBVerticalPageContainerView alloc] initWithFrame:CGRectMake(0, 0, CGRectGetWidth(self.view.bounds), CGRectGetHeight(self.view.bounds))];
        [_containerView registerClass:[TPAskanswerSinglePageView class] forViewReuseIdentifier:NSStringFromClass([TPAskanswerSinglePageView class])];
        _containerView.delegate = self;
        _containerView.dataSource = self;
    }
    return _containerView;;
}


- (NSMutableArray *)array
{
    if (!_array) {
        _array = [NSMutableArray array];
    }
    return _array;
}

@end
